package com.hdl.servlet.cart;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.hdl.entity.MallCart;

/**
 * 删除单个商品
 * @author Administrator
 *
 */
@WebServlet("/deleteItem.let")
public class DeleteItemServlet extends HttpServlet{

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		//获取要删除的商品id
		String mallProductId = req.getParameter("mallProductId");
		
		//获取购物车对象
		MallCart cart = (MallCart) req.getSession().getAttribute("cart");
		
		//调用方法从购物车中删除商品
		cart.removeOne(mallProductId);
		
		//将购物车重新存入session中
		req.getSession().setAttribute("cart", cart);

		//转发
		req.getRequestDispatcher("/myCart.jsp").forward(req, resp);
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
}
